//package com.yunxin.admin.system.api.core.order;
//
//import com.yunxin.admin.system.infra.common.constant.SecurityConstants;
//import com.yunxin.common.result.PageResult;
//import com.yunxin.common.result.Result;
//import com.yunxin.core.application.command.order.OrderUserApplyPageCommand;
//import com.yunxin.core.application.dto.order.OrderUserApplyDetailDTO;
//import com.yunxin.core.application.dto.order.OrderUserApplyPageDTO;
//import com.yunxin.core.application.dto.user.UserInfoPageDTO;
//import com.yunxin.core.application.service.OrderQueryAdminService;
//import com.yunxin.core.domain.model.user.UserIpInfo;
//import com.yunxin.core.domain.model.user.UserIpInfoRepository;
//import com.yunxin.core.infra.persistence.entity.user.UserIpInfoDO;
//import io.swagger.v3.oas.annotations.Operation;
//import io.swagger.v3.oas.annotations.Parameter;
//import io.swagger.v3.oas.annotations.security.SecurityRequirement;
//import io.swagger.v3.oas.annotations.tags.Tag;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.poi.ss.usermodel.Row;
//import org.apache.poi.ss.usermodel.Sheet;
//import org.apache.poi.ss.usermodel.Workbook;
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import java.io.ByteArrayOutputStream;
//import java.io.IOException;
//import java.net.URLEncoder;
//import java.nio.charset.StandardCharsets;
//import java.text.SimpleDateFormat;
//import java.util.List;
//
///**
// * @author zero°
// * @since 2023-05-29
// */
//@Tag(name = "32.订单用户管理")
//@Slf4j
//@RestController
//@RequestMapping("/core/v1/order/user/apply")
//@RequiredArgsConstructor
//public class OrderUserApplyController {
//
//    private final OrderQueryAdminService orderQueryAdminService;
//
//    private final UserIpInfoRepository userIpInfoRepository;
//
//
//    @Operation(summary = "查询用户申请订单详情", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @GetMapping("/getOrderUserApplyDetail")
//    public Result<OrderUserApplyDetailDTO> getOrderUserApplyDetail(@Parameter(description = "申请订单号") @RequestParam("applyOrderNo") String applyOrderNo) {
//        OrderUserApplyDetailDTO result = orderQueryAdminService.getOrderUserApplyDetail(applyOrderNo);
//        return Result.success(result);
//    }
//
//    @Operation(summary = "查询用户最新的用户申请订单详情(用户code)", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @GetMapping("/getLastOrderUserApplyDetail")
//    public Result<OrderUserApplyDetailDTO> getLastOrderUserApplyDetail(@Parameter(description = "用户code") @RequestParam("userCode") String userCode) {
//        OrderUserApplyDetailDTO result = orderQueryAdminService.getLastOrderUserApplyDetail(userCode);
//        return Result.success(result);
//    }
//
//    @Operation(summary = "分页查询用户申请订单列表", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/orderUserApplyPageQuery")
//    public PageResult<OrderUserApplyPageDTO> orderUserApplyPageQuery(@Validated @RequestBody OrderUserApplyPageCommand command) {
//        return orderQueryAdminService.orderUserApplyPageQuery(command);
//    }
//
//    @Operation(summary = "导出采集单列表", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @PostMapping("/export")
//    public ResponseEntity<byte[]> export(@Validated @RequestBody OrderUserApplyPageCommand command) throws IOException {
//        List<OrderUserApplyPageDTO> results = orderQueryAdminService.orderUserApplyPageQueryList(command);
//
////        // 创建工作簿
////        Workbook workbook = new XSSFWorkbook();
////        // 创建工作表
////        Sheet sheet = workbook.createSheet("Sheet1");
////
////        // 创建标题行
////        Row headerRow = sheet.createRow(0);
////        // 设置表头
////
////        headerRow.createCell(2).setCellValue("手机号");
////        headerRow.createCell(3).setCellValue("年龄");
////        headerRow.createCell(4).setCellValue("城市");
////        headerRow.createCell(5).setCellValue("芝麻分");
////        headerRow.createCell(6).setCellValue("渠道来源");
////        headerRow.createCell(7).setCellValue("链接名称");
////        headerRow.createCell(8).setCellValue("分配时间");
////        headerRow.createCell(9).setCellValue("申请时间");
////
////        // 填充数据 从第二行开始
////        int rowNum = 1;
////        for (OrderUserApplyPageDTO dto : results) {
////
////            // 将Date对象格式化为指定格式的字符串
////            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
////            String submitTime = outputFormat.format(dto.getSubmitTime());
////            String allocationTime = outputFormat.format(dto.getAllocationTime());
////
////            // 将Date对象格式化为指定格式的字符串
////            Row row = sheet.createRow(rowNum);
////            row.createCell(0).setCellValue(dto.getApplyOrderNo());
////            row.createCell(1).setCellValue(dto.getUserName());
////            row.createCell(2).setCellValue(dto.getUserPhone());
////            row.createCell(3).setCellValue(dto.getAge());
////            row.createCell(4).setCellValue(dto.getCity());
////            row.createCell(5).setCellValue(dto.getSesameSeedQuota());
////            row.createCell(6).setCellValue(dto.getChannelName());
////            row.createCell(7).setCellValue(dto.getChannelPromotionName());
////            row.createCell(8).setCellValue(allocationTime);
////            row.createCell(9).setCellValue(submitTime);
////
////            rowNum ++ ;
////        }
////        // 将工作簿写入 ByteArrayOutputStream
////        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
////        workbook.write(byteArrayOutputStream);
////
////        // 设置响应头
////        HttpHeaders headers = new HttpHeaders();
////        headers.setContentDispositionFormData("attachment", URLEncoder.encode("采集单列表", StandardCharsets.UTF_8.toString()) + ".xlsx");
////        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//
//        // 返回 Excel 文件的字节数组
////        return new ResponseEntity<>(byteArrayOutputStream.toByteArray(), headers, HttpStatus.OK);
//        return null;
//    }
//
//    @Operation(summary = "导出采集单列表", security = {@SecurityRequirement(name = SecurityConstants.TOKEN_KEY)})
//    @GetMapping("/export_")
//    public ResponseEntity<byte[]> export_ip() throws IOException {
//        String start = "2024-03-12";
//        String end = "2024-03-13";
//        List<UserIpInfo> results = userIpInfoRepository.selectIpList(start,end);
//
//        // 创建工作簿
//        Workbook workbook = new XSSFWorkbook();
//        // 创建工作表
//        Sheet sheet = workbook.createSheet("Sheet1");
//
//        // 创建标题行
//        Row headerRow = sheet.createRow(0);
//
//        headerRow.createCell(0).setCellValue("ip");
//        headerRow.createCell(1).setCellValue("创建时间");
//
//        // 填充数据 从第二行开始
//        int rowNum = 1;
//        for (UserIpInfo dto : results) {
//
//            // 将Date对象格式化为指定格式的字符串
//            SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            String createTime = outputFormat.format(dto.getCreateTime());
//
//            // 将Date对象格式化为指定格式的字符串
//            Row row = sheet.createRow(rowNum);
//            row.createCell(0).setCellValue(dto.getIp());
//            row.createCell(1).setCellValue(createTime);
//
//            rowNum ++ ;
//        }
//        // 将工作簿写入 ByteArrayOutputStream
//        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
//        workbook.write(byteArrayOutputStream);
//
//        // 设置响应头
//        HttpHeaders headers = new HttpHeaders();
//        headers.setContentDispositionFormData("attachment", URLEncoder.encode("采集单列表", StandardCharsets.UTF_8.toString()) + ".xlsx");
//        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//
//        // 返回 Excel 文件的字节数组
//        return new ResponseEntity<>(byteArrayOutputStream.toByteArray(), headers, HttpStatus.OK);
//    }
//
//
//
//}
